package com.sync.utils;

/**
 * 操作系统类：
 * 获取System.getProperty("OSEnvir.name")对应的操作系统
 *  
 */
public class OSEnvir {
	
	//"os.name  os.version os.arch
	private static String OS = System.getProperty("os.name").toLowerCase();
	
	private static OSEnvir _instance = new OSEnvir();
	
	private EPlatform platform;
	
	private OSEnvir(){}
	
	public static boolean isLinux(){
		return OS.indexOf("linux")>=0;
	}
	
	public static boolean isMacOS(){
		return OS.indexOf("mac")>=0&&OS.indexOf("os")>0;
	}
	
	public static boolean isMacOSX(){
		return OS.indexOf("mac")>=0&&OS.indexOf("os")>0&&OS.indexOf("x")>0;
	}
	
	public static boolean isWindows(){
		return OS.indexOf("windows")>=0;
	}
	
	 
	
	public static boolean isSolaris(){
		return OS.indexOf("solaris")>=0;
	}
	
	public static boolean isSunOS(){
		return OS.indexOf("sunos")>=0;
	}
	
	 
	
	public static boolean isFreeBSD(){
		return OS.indexOf("freebsd")>=0;
	}
	
	public static boolean isIrix(){
		return OS.indexOf("irix")>=0;
	}
	
 
	 
	public static boolean isOpenVMS(){
		return OS.indexOf("openvms")>=0;
	}
	
	/**
	 * 获取操作系统名字
	 * @return 操作系统名
	 */
	public static EPlatform getOSname(){
		if (isFreeBSD()) {
			_instance.platform = EPlatform.FreeBSD;
		}else if (isLinux()) {
			_instance.platform = EPlatform.Linux;
		}else if (isMacOS()) {
			_instance.platform = EPlatform.Mac_OS;
		}else if (isMacOSX()) {
			_instance.platform = EPlatform.Mac_OS_X;
		}else if (isOpenVMS()) {
			_instance.platform = EPlatform.OpenVMS;
		}else if (isSolaris()) {
			_instance.platform = EPlatform.Solaris;
		}else if (isSunOS()) {
			_instance.platform = EPlatform.SunOS;
		}else if (isWindows()) {
			_instance.platform = EPlatform.Windows;
		}else{
			_instance.platform = EPlatform.Others;
		}
		return _instance.platform;
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println(OSEnvir.getOSname());
	}

}